package jihelianxi;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Collection02 {
    public static void main(String[] args) {
        //单列集合collection是顶层接口     双列集合map(HasMap,ThreeMap)
        //list集合可以重复(ArrayList,LinkedList),set集合不允许重复(HasSet,ThreeSet)
        //创建Collection集合对象：1，多态 2，具体的实现类Arraylist
        Collect();
    }

    private static void Collect() {
        //Collertion是接口，接口直接不能直接new，接口和实现类对应
        Collection<String> collection = new ArrayList<>();
        //增加信息
        collection.add("11");
        collection.add("111");
        collection.add("1111");
        collection.add("111122");
        System.out.println(collection);
        //删除成功返回true
        //删除失败返回false
        boolean remove = collection.remove("111");
        boolean remove1 = collection.remove("1111");
        boolean remove2 = collection.remove("111111");
        System.out.println(remove);
        System.out.println(remove1);
        System.out.println(remove2);
        //指定条件删除
        //在底层遍历集合中的元素，把每一个元素加到lambda表达式去判断，返回ture,删除成功，返回false，保留不删除
      collection.removeIf((String s)->{
          return s.length()==2;
      });
        System.out.println(collection);
      //清空集合
        collection.clear();
        System.out.println(collection);
        //判断元素是否存在
        boolean a = collection.contains("a");
        System.out.println(a);
//判断集合是否为空
        boolean empty = collection.isEmpty();
        System.out.println(empty);
        //集合的长度
        int size = collection.size();
        System.out.println(size);

    }
}